package customize

import (
	"gitcode.com/G-YT/baoyou/server/model/cms"
)

// Disease 病症
type Disease struct {
	ID       uint       `json:"id" form:"id" gorm:"column:id;comment:id;"`
	Name     string     `json:"name" form:"name" gorm:"column:name;comment:名称;"`                          // 名称
	ParentID int        `json:"parentId" form:"parentId" gorm:"column:parent_id;comment:父节点ID;default:0"` // 父节点
	Sort     int        `json:"sort" form:"sort" gorm:"column:sort;comment:排序;default:0"`                 // 排序
	Children []*Disease `json:"children" gorm:"-"`                                                        // 子节点
}

// DiseaseArticle 病症关联文章
type DiseaseArticle struct {
	DiseaseID    uint         `json:"disease_id" gorm:"column:disease_id;"`
	ArticleID    uint         `json:"article_id" gorm:"column:article_id;"`
	Type         string       `json:"type" gorm:"column:type;"`
	Disease      *Disease     `json:"-" form:"-" gorm:"->;foreignKey:DiseaseID;references:ID;"`
	AudioArticle *cms.Article `json:"-" form:"-" gorm:"->;foreignKey:ArticleID;references:ID;"`
	VideoArticle *cms.Article `json:"-" form:"-" gorm:"->;foreignKey:ArticleID;references:ID;"`
	TextArticle  *cms.Article `json:"-" form:"-" gorm:"->;foreignKey:ArticleID;references:ID;"`
}

// GetChildren 实现TreeNode接口
func (d *Disease) GetChildren() []*Disease {
	return d.Children
}

// SetChildren 实现TreeNode接口
func (d *Disease) SetChildren(children *Disease) {
	d.Children = append(d.Children, children)
}

// GetID 实现TreeNode接口
func (d *Disease) GetID() int {
	return int(d.ID)
}

// GetParentID 实现TreeNode接口
func (d *Disease) GetParentID() int {
	return d.ParentID
}

func (Disease) TableName() string {
	return "by_disease"
}

func (DiseaseArticle) TableName() string {
	return "by_disease_article"
}
